package com.yong.sbd.biz.mybatis.mapper;

import com.yong.sbd.biz.mybatis.entity.SysRole;
import org.apache.ibatis.annotations.*;
import java.util.List;

/**
 * 角色Mapper接口
 *
 * @author Kang Yong
 * @date 2025/10/24
 * @since 1.0.0
 */
@Mapper
public interface SysRoleMapper {

    /**
     * 根据ID查询角色
     *
     * @param id {@link Long}
     * @return {@link SysRole}
     */
    @Select("SELECT * FROM sys_role WHERE id = #{id}")
    SysRole selectById(Long id);

    /**
     * 根据角色编码查询角色
     *
     * @param roleCode {@link String}
     * @return {@link SysRole}
     */
    @Select("SELECT * FROM sys_role WHERE role_code = #{roleCode}")
    SysRole selectByRoleCode(String roleCode);

    /**
     * 查询所有角色
     *
     * @return {@link List<SysRole>}
     */
    @Select("SELECT * FROM sys_role")
    List<SysRole> selectAll();

    /**
     * 插入角色
     *
     * @param role {@link SysRole}
     * @return int
     */
    @Insert("INSERT INTO sys_role(role_name, role_code, description, status) " +
            "VALUES(#{roleName}, #{roleCode}, #{description}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(SysRole role);

    /**
     * 更新角色
     *
     * @param role {@link SysRole}
     * @return int
     */
    @Update("UPDATE sys_role SET role_name=#{roleName}, role_code=#{roleCode}, " +
            "description=#{description}, status=#{status}, update_time=NOW() WHERE id=#{id}")
    int update(SysRole role);

    /**
     * 根据ID删除角色
     *
     * @param id {@link Long}
     * @return int
     */
    @Delete("DELETE FROM sys_role WHERE id = #{id}")
    int deleteById(Long id);
}